'use strict';

const axios = require('axios');
// import axios from 'axios';

// 剩下的代码和之前的一样


module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/user/kh/wxads/code2Session 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			code
		} = data;
		let res = {
			// code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------


		const appid = 'tt4e0838b5d134005401';
		const secret = '9c8886c47c612f3d10e5493a79bb5bfa195ff4f6';


		// 构建请求参数
		const params = {
			appid,
			secret,
			code
		};

		

		// 发送GET请求
		axios.get('https://minigame.zijieapi.com/mgplatform/api/apps/jscode2session', {
				params: params,
			})
			.then(response => {
				// 处理响应数据
				const data = response.data;
				console.log('session_key:', data.session_key);
				console.log('openid:', data.openid);
			})
			.catch(error => {
				// 处理错误
				console.error('请求失败:', error);
			});


		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}